home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSQUERY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-03
|
5KB
|
147 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bsquery.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to remotely verify a user code. The system works
// like this:
// 1) Customer software generates a code
// 2) Customer calls with code and is given response
// 3) Customer enters response into software and it is verified before
// proceding.
//
// The code is an 8 character alphanumeric sequence.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Description: Generate a random query code.
// Parameters: psz 9 byte buffer to recieve code.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_E QueryGenerate(PSZ psz)
{
ULONG ul = Random(0, 10000); // Get a random number
ul *= (ULONG)Pid(); // Multiply by process id
ul *= (ULONG)time(NULL); // Multiply by time
sprintf(psz, "%08lX", ul); // Print to buffer as hex
return ;
}
//----------------------------------------------------------------------------
// Description: Generate a random query code.
// Parameters: psz 9 byte buffer containing code.
// On return, the buffer contains the response.
// pcszKey User defined key unqiue to this application.
// Returns:
//----------------------------------------------------------------------------
VOID FN_E QueryResponse(PSZ psz, PCSZ pcszKey)
{
CRC crc;
Assert(psz && pcszKey);
crc = CrcCalcAppend((PBYTE)psz, strlen(psz)+1, (CRC)0);
crc = CrcCalcAppend((PBYTE)pcszKey, strlen(pcszKey)+1, crc);
sprintf(psz, "%08lX", crc);
return ;
}
//----------------------------------------------------------------------------
// Description: Verify a random query code.
// Parameters: pcsz 9 byte buffer containing code
// pcszResponse 9 byte buffer to recieve code.
// pcszKey User defined key unqiue to this application.
// Returns: TRUE if code was verified
//----------------------------------------------------------------------------
BOOL FN_E QueryVerify(PCSZ pcsz, PCSZ pcszResponse, PCSZ pcszKey)
{
CHAR szResponse[9];
strcpy(szResponse, pcsz);
QueryResponse(szResponse, pcszKey);
//
// This is a programmer back door for testing.
// The response should allow the sum of the hex value of the
// to strings to equal 0xDEADDEAD.
//
#if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS || OS_OS2)
if (DebugMode())
{
if (strcmpi(pcszResponse, "DEADDEAD") == 0)
return TRUE;
}
#endif
return stricmp(szResponse, pcszResponse) == 0;
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN QueryTest(SHORT sTest)
{
static PCSZ pcszKey = "This is a test";
CHAR szCode[9], szResponse[9];
NOTUSED(sTest);
QueryGenerate(szCode);
strcpy(szResponse, szCode);
QueryResponse(szResponse, pcszKey);
Output(
" Code: %s\n"
"Response: %s\n"
"Verified: %s\n",
szCode, szResponse,
(QueryVerify(szCode, szResponse, pcszKey) ? "YES": "NO"));
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------